package com.tcreditdemo;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import java.util.ArrayList;

public class HomeFragment extends BaseFragment implements MeDetailAdapter.OnSwitchCompatChangerListener{

    private RecyclerView recyclerView;
    private ArrayList<ArrayList<Integer>> datas;
    private ArrayList<Integer> data0;
    private ArrayList<Integer> data1;
    private ArrayList<Integer> data2;
    private HomeRecyclerviewAdapter adapter;

    public boolean switchstate=false;


    @Override
    public void onHiddenChanged(boolean hidden) {

    }

    @Override
    public int getlayout() {
        return R.layout.home_fragment_view;
    }

    @Override
    public void initialize() {
        initdata();
        recyclerView = view.findViewById(R.id.recycler);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        adapter = new HomeRecyclerviewAdapter(getActivity(), datas,switchstate);
        recyclerView.setAdapter(adapter);
        MeDetailAdapter.setOnSwitchCompatChangerListener(this);
    }

    public void initdata(){
        datas = new ArrayList<>();
        data0=new ArrayList<>();
        data1=new ArrayList<>();
        data2=new ArrayList<>();
        for (int i=0;i<5;i++){
            data0.add(i);
            if (i<4){
                data1.add(i);
            }
            if (i<2){
                data2.add(i);
            }
        }
        datas.add(data0);
        datas.add(data1);
        datas.add(data2);
    }

    @Override
    public void getstate(boolean state) {
//        if (state){
            if (switchstate){
                switchstate=false;
            }else {
                switchstate=true;
            }
       // }
        adapter = new HomeRecyclerviewAdapter(getActivity(), datas,switchstate);
        recyclerView.setAdapter(adapter);

    }
}
